home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / scsiDevice.h < prev    next >
C/C++ Source or Header  |  1991-08-11  |  7KB  |  163 lines

  1. /*
  2.  * scsiDevice.h --
  3.  *
  4.  *    Declarations of Sprite interface to SCSI devices.  
  5.  *    This file defines the interface to SCSI devices which consists 
  6.  *    of three operations: Attach the device, Release the device, and
  7.  *    send a SCSI command block to the device. 
  8.  *
  9.  *    INTERFACE SUMMARY: 
  10.  *
  11.  *    To interface to a SCSI device, the SCSI command formatter must first
  12.  *    attach the device.  This is done by calling DevScsiAttachDevice() with
  13.  *    the Fs_Device structure for the device. DevScsiAttachDevice 
  14.  *    returns a ScsiDeviceHandle that contains the queue to insert 
  15.  *    scsi command blocks for the device. The handle also 
  16.  *    contains the procedure to call to release the device.
  17.  *       
  18.  *
  19.  * Copyright 1989 Regents of the University of California
  20.  * Permission to use, copy, modify, and distribute this
  21.  * software and its documentation for any purpose and without
  22.  * fee is hereby granted, provided that the above copyright
  23.  * notice appear in all copies.  The University of California
  24.  * makes no representations about the suitability of this
  25.  * software for any purpose.  It is provided "as is" without
  26.  * express or implied warranty.
  27.  *
  28.  * $Header: /sprite/src/kernel/dev/RCS/scsiDevice.h,v 9.1 90/09/11 12:13:37 rab Exp $ SPRITE (Berkeley)
  29.  */
  30.  
  31. #ifndef _SCSIDEVICE
  32. #define _SCSIDEVICE
  33.  
  34. #include "list.h"
  35. #include "devQueue.h"
  36. #include "user/fs.h"
  37. #include "fs.h"
  38.  
  39. /*
  40.  * A device attached to a SCSI Bus is described by the following stucture. 
  41.  * A pointer to a ScsiDevice is returned by the DevScsiAttachDevice
  42.  * routine and contains the device queue to use to 
  43.  * send commands to the device. The fields of the structure are 
  44.  * initialize by the attached routine and should not be modified or copied
  45.  * by the SCSI formatting routines. The pointer passed to the 
  46.  * and releaseProc procedures should be the same value returned by the
  47.  * attachProc. 
  48.  */
  49.  
  50. typedef struct ScsiDevice {
  51.     DevQueue      devQueue;         /* Queue to send request for this 
  52.                       * device. Once the request has been
  53.                       * processed, the caller 
  54.                       * caller by calling function sepcified
  55.                       * in the SCSICmd structure.  */
  56.     char     *locationName;         /* A string used to identify the device's
  57.                       * location in error messages produced
  58.                       * the SCSI formatting routines. An 
  59.                       * Example would be:
  60.                       * "HBA 2 Bus 1 Target 6 LUN 2". */
  61.     int        LUN;              /* SCSI Logical unit number of device.
  62.                        * This is stored here because the
  63.                        * SCSI command formatter needs to 
  64.                        * know the LUN to build command
  65.                        * blocks. */
  66.     ReturnStatus (*releaseProc)();   /* Routine to release the system 
  67.                       * resources used by the device. Calling
  68.                       * sequence defined below. */
  69.     int     maxTransferSize;         /* Maximum size of data transfer to 
  70.                       * this device supported by the HBA. */
  71.     int         inquiryLength;         /* Length in bytes of the inquiryData 
  72.                       * pointed to by inquiryDataPtr. */
  73.     char     *inquiryDataPtr;    /* Data return by the INQUIRY command 
  74.                       * sent to the device. */
  75.     int        referenceCount;         /* Count of number of references to this
  76.                       * device handle. */
  77. } ScsiDevice;
  78.  
  79. /*
  80.  * The ScsiCmd data structure contains the information that a SCSI device 
  81.  * to execute a SCSI command. It is the object enqueue on a SCSI device's 
  82.  * request queue. Note that the bytes of the SCSI command block over 16 
  83.  * bytes directly follow this data structure.
  84.  */
  85. struct ScsiCmd {
  86.     List_Links    queuePtr;    /* List for queueing in HBA. Because we
  87.                  * use the DevQueue routines this element
  88.                  * MUST be the first in the structure.     */
  89.     Boolean    dataToDevice;    /* TRUE -> data is transferred to the device.
  90.                  * FALSE -> data is transferred from the device.
  91.                  * Meaningless if bufferLen is 0. */
  92.     int        bufferLen;    /* The length of the data buffer in bytes. */
  93.     Address    buffer;        /* The data buffer for this command. */
  94.     int        (*doneProc)();  /* Routine to called when command completes.
  95.                      * See below for its calling sequence.  */
  96.     ClientData clientData;    /* A word of data available to the caller. 
  97.                  * This item is not changed by the Device. */
  98.     int           commandBlockLen;    /* Length of the SCSI command block. The
  99.                  * data of the SCSI command block immediately
  100.                  * follows this data structure and continues
  101.                  * for commandBlockLen bytes. */
  102.     char    commandBlock[16]; /* The first 16 bytes of the SCSI command
  103.                    * block.  The rest of the command directly
  104.                    * follows the first 16 bytes. */
  105. };
  106. typedef struct ScsiCmd ScsiCmd;
  107.  
  108. /*
  109.  * Upon command completion the routine specified by doneProc in the
  110.  * ScsiCmd data structure is called with the following arguments:
  111.  *    (*doneProc)(scsiCmdPtr, errorCode, scsiStatusByte, 
  112.  *            amountTransferred, senseDataLen, senseDataPtr);
  113.  *    where
  114.  * ScsiCmd   *scsiCmdPtr  - The scsiCmdPtr argument passed to sendCmdProc.
  115.  * ReturnStatus errorCode  - The error code from the HBA.
  116.  * unsigned char scsiStatusByte - The scsi status byte as returned by the SCSI 
  117.  *                      command.
  118.  * int     amountTransferred - Number of bytes of data transferred by this 
  119.  *                 command.
  120.  * int   senseDataLen -   The length in bytes of the SCSI sense info returned.
  121.  *              This number will be zero useless the scsiStatusByte
  122.  *              has the SCSI check condition bit set.
  123.  * char *senseDataPtr -   Pointer to scsi sense blocks.  This block will no
  124.  *              longer be valid once the call back routine returns.
  125.  *              (i.e. You must copy it if you want to save it.)
  126.  * 
  127.  * scsiDoneProc may be called at interrupt level so it should use
  128.  * appropriate locking and be relatively simple. Also, scsiDoneProc
  129.  * maybe called before the sendCmdProc proc returns.
  130.  */
  131.  
  132.  
  133. /*
  134.  * DevScsiSendCmd is normally encoded as macros for speed and reduced
  135.  * calling depth.
  136.  * If lint is being run we use the real routines in devScsiDevice.c to 
  137.  * permit type checking. Documentation on the calling sequence is found
  138.  * in devScsiDevice.c.
  139.  */
  140. #ifndef lint
  141. #define    DevScsiSendCmd(handlePtr, scsiCmdPtr) \
  142.     (Dev_QueueInsert((handlePtr)->devQueue,(List_Links *) (scsiCmdPtr)))
  143. #else
  144. extern void          DevScsiSendCmd();
  145. #endif
  146.  
  147. extern ScsiDevice *DevScsiAttachDevice _ARGS_((Fs_Device *devicePtr,
  148.     void (*insertProc)()));
  149. extern ReturnStatus DevScsiSendCmdSync _ARGS_((ScsiDevice *scsiDevicePtr,
  150.     ScsiCmd *scsiCmdPtr, unsigned char *statusBytePtr,
  151.     int *amountTransferredPtr, int *senseBufferLenPtr, Address senseBufferPtr));
  152. extern ReturnStatus DevScsiReleaseDevice _ARGS_((ScsiDevice *scsiDevicePtr));
  153. extern ReturnStatus DevScsiTestReady _ARGS_((ScsiDevice *scsiDevicePtr));
  154. extern ReturnStatus DevScsiStartStopUnit _ARGS_((ScsiDevice *scsiDevicePtr,
  155.     Boolean start));
  156. extern ReturnStatus DevScsiIOControl _ARGS_((ScsiDevice *devPtr,
  157.     Fs_IOCParam *ioctlPtr, Fs_IOReply *replyPtr));
  158. extern ScsiDevice *DevNoHBAAttachDevice _ARGS_((Fs_Device *devicePtr,
  159.     void (*insertProc)()));
  160.  
  161. #endif /* _SCSIDEVICE */
  162.  
  163.